package com.wuzuqing.android.eightdiagrams

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
import com.wuzuqing.android.eightdiagrams.dao.BaZhiHistory
import com.wuzuqing.android.eightdiagrams.db.DbManager
import com.wuzuqing.android.eightdiagrams.utils.*
import java.util.*

class BaZiHistoryActivity : BaseActivity() {
    lateinit var vRcvHistory: RecyclerView


    @SuppressLint("SimpleDateFormat")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_bazi_history)
        vRcvHistory = findViewById(R.id.historyRcv)
        initResultRcv()
    }


    private fun initResultRcv() {
        vRcvHistory.layoutManager = LinearLayoutManager(this)
        vRcvHistory.adapter = BaZhiHistoryAdapter().also {
            val list = DbManager.getInstance().db.baZhiHistoryDao().queryAll()
            it.setList(list)
            it.setOnItemClickListener(object :BaseAdapter.OnItemClickListener<BaZhiHistory>{
                override fun onItemClick(data: BaZhiHistory, position: Int) {
                    startActivity(Intent(this@BaZiHistoryActivity,BaZiActivity::class.java).apply {
                        putExtra("data",data)
                    })
                    finish()
                }
            })
        }
//        val height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics).toInt()
//        val dividerItemDecoration = GridDividerItemDecoration(this, height, true)
//        vRcvResult.addItemDecoration(dividerItemDecoration)
    }

}
